Sympy polynomials with `mpfr` coefficients?
NickName:leewz Ask DateTime:2015-02-21T03:12:51

Sympy polynomials with `mpfr` coefficients?

I want to use Sympy's polynomials, but I also want to use higher-precision coefficients.

Just Doing It seems to give me polynomials with sympy.core.numbers.float coefficients.

import sympy
from sympy import Poly
from sympy.abc import x
from gmpy2 import mpfr, get_context

get_context().precision = 150

#float64 can't tell this from 1.0
one_and_change = mpfr('1.0000000000000000000000000000000000001')
#mpfr('1.0000000000000000000000000000000000001000000005',150)

p = [one_and_change]
px = Poly(p, x)

print(px)
# Poly(1.0, x, domain='RR')
print(px.is_one)
# True
print(type(px.all_coeffs()[0]))
# <class 'sympy.core.numbers.Float'>

I've also tried sympy.mpmath.mpf, with the same results.

This also didn't work:[1]

domain = sympy.polys.domains.realfield.RealField(150)
px = Poly(p, x, domain=domain)
print(type(px.all_coeffs()[0]))
# <class 'sympy.core.numbers.Float'>

Copyright Notice:Content Author:「leewz」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/28636499/sympy-polynomials-with-mpfr-coefficients

More about “Sympy polynomials with `mpfr` coefficients?” related questions